﻿using System;
using System.Collections;

namespace ExFlash.Records
{
    public class MorphFillStyleArray : ISwfSerializable, ICollection
    {
        public ushort FillStyleCount
        {
            get;
            protected set;
        }

        public MorphFillStyle[] FillStyles
        {
            get;
            protected set;
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            FillStyleCount = reader.ReadByte();

            if (FillStyleCount == 0xFF)
            {
                FillStyleCount = reader.ReadUInt16();
            }

            FillStyles = new MorphFillStyle[FillStyleCount];

            for (int i = 0; i < FillStyleCount; i++)
            {
                FillStyles[i] = new MorphFillStyle();
                FillStyles[i].SwfDeserialize(reader);
            }
            
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            return FillStyles.GetEnumerator();
        }

        #endregion

        #region ICollection Members

        public void CopyTo(Array array, int index)
        {
            FillStyles.CopyTo(array, index);
        }

        public int Count
        {
            get { return FillStyleCount; }
        }

        public bool IsSynchronized
        {
            get { return FillStyles.IsSynchronized; }
        }

        public object SyncRoot
        {
            get { return FillStyles.SyncRoot; }
        }

        #endregion
    }
}
